<?php namespace Home\Controller;
use Hdphp\Controller\Controller;
class ListController extends Controller{
	public function index(){
		$tid=Q('get.tid',0,'intval');
		//类型属性分类
		//一级菜单分类
		$goodsAttr=new \Common\Model\GoodsAttr;
		$typeAttr=new \Common\Model\TypeAttr;
		$goods=new \Common\Model\Goods;
		//定义一个空数组，用来重组数组
		$dataTG=array();
		$typeGoods=$typeAttr->join('goods_attr','beautiful_type_attr.taid','=','beautiful_goods_attr.taid')->where('class=0')->where(array('tid'=>$tid))->get();
		//重组后的数组，获得了短袖所对应的gtid用于提交gtid选择商品
		foreach ($typeGoods as $k => $v) {
			$dataTG[$v['taid']]['name']=$v['taname'];
			$dataTG[$v['taid']]['value'][$v['gtvalue']]=$v['gtvalue'];
		}
//		p($dataTG);
		foreach ($dataTG as $k => $v) {
			foreach ($v['value'] as $key => $value) {
				
				$dataTG[$k]['value1'][]=$value;
//				unset($dataTG[$k]['value'][$key]);
			}
		}
		$nn=array();
		foreach ($dataTG as $k => $v) {
			$nn[]=$v;
		}
//		p($dataTG);
//		p($nn);die;
		$showData=array_slice($nn, 0,3);
		$hideData=array_slice($nn, 4,6);
		View::with('showData',$showData);
		View::with('hideData',$hideData);
//		p($tid);
//		p($showData);
		//所有商品数据
		$item=$goods->where(array('tid'=>$tid))->get();
		View::with('item',$item);
//		p($item);

		if(Q('get.gtvalue')){
//			p($_GET);
			$hh=$_GET;
			$gtvalue=Q('get.gtvalue');
			$hh['k']=explode('_', $hh['k']);
//			p($hh);
			$got=array();
			foreach($hh['k'] as $k=>$v){
				if($v!=0){
					$hh['k'][$k]=explode('-', $v);
//					$goodsT=$hh['k'][$k];
				}
			}
			foreach ($hh['k'] as $k => $v) {
				if($v!=0){
					foreach($v as $key=>$val){
						$got[]=$val;
					}
				}
			}
//			p($hh);
//			p($got);
//			p(count($got));
			$num=count($got);
			$bm=array_count_values($got);
//			p($bm);
			$itemMeg=array();
			$pp=array();
			foreach ($bm as $k => $v) {
					$pp[]=$v;
			}
//			p($pp);//缺少103   103-105
//						102    104--105
			$maxs=max($pp);
			foreach ($bm as $k => $v) {
				if($v!=1&&$v==$maxs){
//					p($v);
//					$goods=new \Common\Model\Goods;
					$itemData=$goods->where(array('gid'=>$k))->find();
					$itemMeg[]=$itemData;
					break;
//					p($itemMeg);die;
				}else{
//					p($v);
					$itemData=$goods->where(array('gid'=>$k))->find();
					$itemMeg[]=$itemData;
//					p($itemMeg);die;
				}
			}
			$tid=Q('get.tid');
//			p($itemMeg);
			View::with('itemMeg',$itemMeg);
		}
		View::make();
	}
public function get(){

		$aa=$_GET;

		$key=$aa['aa'];//行0
		$kv=$aa['bb'];//列1
//		p($key);p($kv);
		$cc=array();
		$gg=array();
		$aa['k']=explode('_',$aa['k']);
//		p($aa);
		
		foreach($aa['k'] as $k=>$v){
//			p($aa['k']);
			if($k==$key){
				$goodsAttr=new \Common\Model\GoodsAttr;
				$ff=$goodsAttr->where(array('gtvalue'=>$aa['gtvalue']))->get();
//				p($ff);
				foreach ($ff as $ky => $val) {
					$gg[]=$val['gid'];
					
				}
//				p($gg);die;
				$gg=implode('-', $gg);
				$aa['k'][$k]=$gg;
			}
		}

//		p($gg);
		
//		p($_GET);

		$aa['k']=implode('_', $aa['k']);
		$cc=$aa;
//		$cc['gtvalue']=urlencode($cc['gtvalue']);
//		$cc['k']=urlencode($cc['k']);
//		$cc['tid']=urlencode($cc['tid']);
		
//		die;
//		$_GET['a']='index';
//		p($cc);die;
		go(U('list/index',array('k'=>$cc['k'],'tid'=>$cc['tid'],'gtvalue'=>$cc['gtvalue'])));
	}
}


 ?>